From: C. Scott Ananian Date: Tue, 28 Feb 2017 20:56:01 +0000 (-0500) Subject: Export list of languages which will trigger language conversion X-Git-Tag: 1.31.0-rc.0~3926^2 X-Git-Url: http://git.cyclocoop.org//%22http:/%22.attribut_html%28%24lesurls%5B%24numero%5D%29.%22/%22?a=commitdiff_plain;ds=sidebyside;h=1824778e44c08c44857ac154d7633a7f598e08da;p=lhc%2Fweb%2Fwiklou.git Export list of languages which will trigger language conversion LanguageConverter is enabled on a per-page basis, based on the page language and whether it implements `$lang->getConverter()`. Export this in siteinfo so that Parsoid knows whether it should parse language converter markup on a given page (based on the page language). Bug: T153341 Change-Id: I010aa3812051725166ab79ea5ee3eaf56615fe94 --- diff --git a/RELEASE-NOTES-1.29 b/RELEASE-NOTES-1.29 index 9f2c850b70..98834745f1 100644 --- a/RELEASE-NOTES-1.29 +++ b/RELEASE-NOTES-1.29 @@ -106,6 +106,8 @@ production. * Added action=validatepassword to validate passwords for the account creation and password change forms. * action=purge now requires a POST. +* There is a new `languagevariants` siprop for action=query&meta=siteinfo, + which returns a list of languages with active LanguageConverter instances. === Action API internal changes in 1.29 === * New methods were added to ApiBase to handle errors and warnings using i18n diff --git a/includes/api/ApiQuerySiteinfo.php b/includes/api/ApiQuerySiteinfo.php index a8c037ec6a..cc302dcebf 100644 --- a/includes/api/ApiQuerySiteinfo.php +++ b/includes/api/ApiQuerySiteinfo.php @@ -88,6 +88,9 @@ class ApiQuerySiteinfo extends ApiQueryBase { case 'languages': $fit = $this->appendLanguages( $p ); break; + case 'languagevariants': + $fit = $this->appendLanguageVariants( $p ); + break; case 'skins': $fit = $this->appendSkins( $p ); break; @@ -713,6 +716,49 @@ class ApiQuerySiteinfo extends ApiQueryBase { return $this->getResult()->addValue( 'query', $property, $data ); } + // Export information about which page languages will trigger + // language conversion. (T153341) + public function appendLanguageVariants( $property ) { + $langNames = LanguageConverter::$languagesWithVariants; + if ( $this->getConfig()->get( 'DisableLangConversion' ) ) { + // Ensure result is empty if language conversion is disabled. + $langNames = []; + } + sort( $langNames ); + + $data = []; + foreach ( $langNames as $langCode ) { + $lang = Language::factory( $langCode ); + if ( $lang->getConverter() instanceof FakeConverter ) { + // Only languages which do not return instances of + // FakeConverter implement language conversion. + continue; + } + $data[$langCode] = []; + ApiResult::setIndexedTagName( $data[$langCode], 'variant' ); + ApiResult::setArrayType( $data[$langCode], 'kvp', 'code' ); + + $variants = $lang->getVariants(); + sort( $variants ); + foreach ( $variants as $v ) { + $fallbacks = $lang->getConverter()->getVariantFallbacks( $v ); + if ( !is_array( $fallbacks ) ) { + $fallbacks = [ $fallbacks ]; + } + $data[$langCode][$v] = [ + 'fallbacks' => $fallbacks, + ]; + ApiResult::setIndexedTagName( + $data[$langCode][$v]['fallbacks'], 'variant' + ); + } + } + ApiResult::setIndexedTagName( $data, 'lang' ); + ApiResult::setArrayType( $data, 'kvp', 'code' ); + + return $this->getResult()->addValue( 'query', $property, $data ); + } + public function appendSkins( $property ) { $data = []; $allowed = Skin::getAllowedSkins(); @@ -851,6 +897,7 @@ class ApiQuerySiteinfo extends ApiQueryBase { 'rightsinfo', 'restrictions', 'languages', + 'languagevariants', 'skins', 'extensiontags', 'functionhooks', diff --git a/includes/api/i18n/en.json b/includes/api/i18n/en.json index f9de7255cd..b90eb506a0 100644 --- a/includes/api/i18n/en.json +++ b/includes/api/i18n/en.json @@ -1139,6 +1139,7 @@ "apihelp-query+siteinfo-paramvalue-prop-rightsinfo": "Returns wiki rights (license) information if available.", "apihelp-query+siteinfo-paramvalue-prop-restrictions": "Returns information on available restriction (protection) types.", "apihelp-query+siteinfo-paramvalue-prop-languages": "Returns a list of languages MediaWiki supports (optionally localised by using $1inlanguagecode).", + "apihelp-query+siteinfo-paramvalue-prop-languagevariants": "Returns a list of language codes for which [[mw:LanguageConverter|LanguageConverter]] is enabled, and the variants supported for each.", "apihelp-query+siteinfo-paramvalue-prop-skins": "Returns a list of all enabled skins (optionally localised by using $1inlanguagecode, otherwise in the content language).", "apihelp-query+siteinfo-paramvalue-prop-extensiontags": "Returns a list of parser extension tags.", "apihelp-query+siteinfo-paramvalue-prop-functionhooks": "Returns a list of parser function hooks.", diff --git a/includes/api/i18n/qqq.json b/includes/api/i18n/qqq.json index d4380c2b9c..cca3a3c6e6 100644 --- a/includes/api/i18n/qqq.json +++ b/includes/api/i18n/qqq.json @@ -1064,6 +1064,7 @@ "apihelp-query+siteinfo-paramvalue-prop-rightsinfo": "{{doc-apihelp-paramvalue|query+siteinfo|prop|rightsinfo}}", "apihelp-query+siteinfo-paramvalue-prop-restrictions": "{{doc-apihelp-paramvalue|query+siteinfo|prop|restrictions}}", "apihelp-query+siteinfo-paramvalue-prop-languages": "{{doc-apihelp-paramvalue|query+siteinfo|prop|languages}}", + "apihelp-query+siteinfo-paramvalue-prop-languagevariants": "{{doc-apihelp-paramvalue|query+siteinfo|prop|languagevariants}}", "apihelp-query+siteinfo-paramvalue-prop-skins": "{{doc-apihelp-paramvalue|query+siteinfo|prop|skins}}", "apihelp-query+siteinfo-paramvalue-prop-extensiontags": "{{doc-apihelp-paramvalue|query+siteinfo|prop|extensiontags}}", "apihelp-query+siteinfo-paramvalue-prop-functionhooks": "{{doc-apihelp-paramvalue|query+siteinfo|prop|functionhooks}}",